<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('图片列表')"/>
    <th:block th:include="common/include :: layout-latest-css"/>
    <th:block th:include="common/include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 图片目录
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="catalog()" title="管理目录"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新目录"><i
                        class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="album-form">
                    <input type="hidden" id="catalogId" name="catalogId">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                资源url：<input type="text" name="sourceUrl"/>
                            </li>
                            <li>
                                照片描述：<input type="text" name="desca"/>
                            </li>

                            <li>
                                是否发布：<select name="isRelease" th:with="type=${@dict.getType('sys_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                是否下载：<select name="isDown" th:with="type=${@dict.getType('sys_yes_no')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                            </li>

                            <li class="select-time">
                                <label>创建时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                       name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                       name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="content:album:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
                   shiro:hasPermission="content:album:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                   shiro:hasPermission="content:album:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: layout-latest-js"/>
<th:block th:include="common/include :: ztree-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('content:album:edit')}]];
    var removeFlag = [[${@permission.hasPermi('content:album:remove')}]];
    var prefix = ctx + "content/album";
    var module = "album";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryAlbumList();
        queryCatalogTree();
    });

    function queryAlbumList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "图片",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '照片id',
                    visible: false
                },
                {
                    field: 'sourceUrl',
                    title: '资源url',
                    sortable: true
                },
                {
                    field: 'desca',
                    title: '照片描述',
                    sortable: true
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '是否发布',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return releaseTools(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '是否可以下载',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return downTools(row);
                    }
                },
                {
                    field: 'releaseTime',
                    title: '发布时间'
                },
                {
                    field: 'downNum',
                    title: '下载次数'
                },
                {
                    field: 'albumSort',
                    title: '顺序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    };

    function queryCatalogTree() {
        var url = ctx + "content/catalog/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick,
            ajaxParams: {
                module: module
            }
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#catalogId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryCatalogTree();
    });

    /* 图片管理-目录 */
    function catalog() {
        var url = ctx + "content/catalog?module=" + module;
        $.modal.openTab("目录管理", url);
    }

    function releaseTools(row) {
        if (row.isRelease == "N") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableRelease(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableRelease(\'' + row.id + '\')"></i> ';
        }
    }

    /* 图片展示-启用 */
    function enableRelease(id) {
        $.modal.confirm("确认要展示图片吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "isRelease": "Y"});
        })
    }

    /* 图片展示-停用 */
    function disableRelease(id) {
        $.modal.confirm("确认要隐藏图片吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "isRelease": "N"});
        })
    }

    function downTools(row) {
        if (row.isDown == "N") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enableDown(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disableDown(\'' + row.id + '\')"></i> ';
        }
    }

    /* 图片展示-启用 */
    function enableDown(id) {
        $.modal.confirm("确认要开启下载吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "isDown": "Y"});
        })
    }

    /* 图片展示-停用 */
    function disableDown(id) {
        $.modal.confirm("确认要关闭下载吗？", function () {
            $.operate.post(prefix + "/edit", {"id": id, "isDown": "N"});
        })
    }

</script>
</body>
</html>
